/**
 * auditDetail.js
 * 航延补偿数据共享
 */
export default {
  namespace: 'auditDetail',
  state: {
    payMethods: {}, //收款方式
    compensationAmount: {
      baseAmount: 200,
      childAmount: 50,
      babyAmount: 10,
    }, //补偿金额
    baseData: {
      serviceTerminal: '',//服务航站
      delayTime: '',//延误时长
    },
    remark: '',//标记
    passengers: [], //选中的旅客
    passengersIds: [], //选中的旅客的id
    tags:[], // tabs列表
    cleartag:[], // 要关闭的tab
    setTags:null, // 操作tabs的方法
  },
  reducers: {
    changePayMethods(state, { payload }) {
      //此处必须返回一个新的state对象 不能直接改变原有state
      return { ...state, payMethods: payload.payMethods };
    },
    changebaseData(state, { payload }) {
      return { ...state, baseData: payload.baseData };
    },
    changeRemark(state, { payload }) {
      return { ...state, remark: payload.remark };
    },
    changePassengers(state, { payload }) {
      return { ...state, passengers: payload.passengers };
    },
    changePassengersIds(state, { payload }) {
      return { ...state, passengersIds: payload.passengersIds };
    },
    changeCompensationAmount(state, { payload }) {
      return { ...state, compensationAmount: payload.compensationAmount };
    },
    // 重置数据
    resetUploadList(state, { payload }) {
      return {
        ...state,
        payMethods: {}, //收款方式
        compensationAmount: {
          baseAmount: 200,
          childAmount: 50,
          babyAmount: 10,
        }, //补偿金额
        baseData: {
          serviceTerminal: '',//服务航站
          delayTime: '',//延误时长
        },
        remark: '',//标记
        passengers: [], //选中的旅客
        passengersIds: [], //选中的旅客的id
      };
    },
    // 操作tabs
    changeTabs(state, { payload }) {
      return { ...state, ...payload };
    },
    // 过滤掉关闭的tab
    removeTabs(state, { payload }) {
      state.cleartag = state.tags.filter(item => item.path === payload.removeTabsPathname);
      state.tags = state.tags.filter(item => item.path !== payload.removeTabsPathname);
      return { ...state };
    },
  },
};
